package zhao.tx.eecs.zhao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

import zhao.tx.eecs.R;
import zhao.tx.eecs.common.CommonActivity;

public class PD_Shebeilist extends CommonActivity {
	private ListAdapter adapter = null ;
	private List<Map<String, Object>> list = null;//数据
	private Handler handler=new Handler(){//http返回的处理
		@Override
		public void handleMessage(Message msg) {
			
		}
	};
		
    @Override
    public void onCreate(Bundle savedInstanceState) {    	
        super.onCreate(savedInstanceState);
        setContentView( R.layout.pd_shebeilist);
        super.listViewAll = (ListView) findViewById(android.R.id.list);
        
        
        initDate();
    }
   
	//点击实现listview数据刷新，
	class listViewOnclickListener implements OnItemClickListener {
		
		@Override
		public void onItemClick(AdapterView<?> listt, View view, int position,long id) {			
			
		}
	}
	
	/**
	 * 设置一个适配器(把该适配器绑定到ListView上面)
	 */
	class ListAdapter extends BaseAdapter{
		private LayoutInflater inflater;
		public final class Holder {
			TextView txt1;
			TextView txt2;
			TextView txt3;
			TextView txt4;
			TextView txt5;
			TextView txt6;
		}
       
		public ListAdapter(Context context){        	
        	this.inflater = LayoutInflater.from(context);
        }
		@Override
		public int getCount() {
			return list.size();
		}

		@Override
		public Object getItem(int position) {
			return list.get(position);
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(final int position, View convertView, ViewGroup parent) {
			Holder holder;
			if (convertView == null) {
				holder = new Holder();
				convertView = inflater.inflate(R.layout.shebeilist_item, null);
				holder.txt1 = (TextView) convertView.findViewById(R.id.no);
				holder.txt2 = (TextView) convertView.findViewById(R.id.type);
				holder.txt3 = (TextView) convertView.findViewById(R.id.name);
				holder.txt4 = (TextView) convertView.findViewById(R.id.model);
				holder.txt5 = (TextView) convertView.findViewById(R.id.place);
				holder.txt6 = (TextView) convertView.findViewById(R.id.jg);
				convertView.setTag(holder);
			} else {
				holder = (Holder) convertView.getTag();
			}
			
			if(position==0){
				holder.txt1.setText("设备编号");
				holder.txt2.setText("设备类型");
				holder.txt3.setText("设备名称");
				holder.txt4.setText("设备型号");
				holder.txt5.setText("所在处所");
				holder.txt6.setText("所在机柜");	
				
//				holder.txt1.setTextSize(13);
//				holder.txt2.setTextSize(13);
//				holder.txt3.setTextSize(13);
//				holder.txt4.setTextSize(13);
//				holder.txt5.setTextSize(13);
//				holder.txt6.setTextSize(13);
				
			}
			else {
				holder.txt1.setText((String) list.get(position).get("v1"));
				holder.txt2.setText((String) list.get(position).get("v2"));
				holder.txt3.setText((String) list.get(position).get("v3"));
				holder.txt4.setText((String) list.get(position).get("v4"));
				holder.txt5.setText((String) list.get(position).get("v5"));
				holder.txt6.setText((String) list.get(position).get("v6"));
			}
			
			
			
			return convertView;
		}		
	}
	
	 
    /**
     * 获取ListView的数据
     * @return
     */
	private List<Map<String, Object>> getDate() {
		
		List<Map<String, Object>> listLitong = new ArrayList<Map<String, Object>>();
		Map<String, Object> maplitong = new HashMap<String, Object>();		
		maplitong.put("v1", "08989891237");
		maplitong.put("v2", "联锁设备");
		maplitong.put("v3", "工控机");
		maplitong.put("v4", "abc");
		maplitong.put("v5", "机械室机械室机械室");
		maplitong.put("v6", "1");
		listLitong.add(maplitong);
		
		maplitong = new HashMap<String, Object>();
		maplitong.put("v1", "08989891237");
		maplitong.put("v2", "联锁设备");
		maplitong.put("v3", "工控机");
		maplitong.put("v4", "abc");
		maplitong.put("v5", "机械室");
		maplitong.put("v6", "1");
		listLitong.add(maplitong);
		
		maplitong = new HashMap<String, Object>();
		maplitong.put("v1", "08989891123");
		maplitong.put("v2", "联锁设备daf");
		maplitong.put("v3", "工控机工控机");
		maplitong.put("v4", "abcdfgdadsf");
		maplitong.put("v5", "机械室caokoanfd");
		maplitong.put("v6", "1");
		listLitong.add(maplitong);
		
		maplitong = new HashMap<String, Object>();
		maplitong.put("v1", "08989891237");
		maplitong.put("v2", "联锁设备");
		maplitong.put("v3", "工控机工控机工控机");
		maplitong.put("v4", "abc");
		maplitong.put("v5", "机械室");
		maplitong.put("v6", "1");
		listLitong.add(maplitong);
		
		maplitong = new HashMap<String, Object>();
		maplitong.put("v1", "08989891237");
		maplitong.put("v2", "联锁设备");
		maplitong.put("v3", "工控机");
		maplitong.put("v4", "abc");
		maplitong.put("v5", "机械室机械室机械室");
		maplitong.put("v6", "1");
		listLitong.add(maplitong);
			  
		return listLitong;
	}
  
	/**
	 * 拿到整个数据List的大小</br> 如果List不等于空 或者 List的大小大于零</br>
	 * 实例化一个自定义的适配器,把自定义的适配器绑定到控件ListView上面</br>
	 * 实例化一个自定义的监听器,把自定义的监听器绑定到控件ListView上面</br> 判断屏幕的密度 </br> 如果密度小于1.0
	 * 密度等于1.5</br> 就给ListView手动设置宽度和高度</br>
	 */
	private void initDate(){
		list = getDate();
		if(list != null && list.size() > 0 ){
			adapter = new ListAdapter(this);
			super.listViewAll.setAdapter(adapter);
			super.listViewAll.setOnItemClickListener(new listViewOnclickListener());			
		}
	}
	public void btn_shebei_click(View v) {	
		 
		 Intent intent = new Intent();		 
		 intent.setClass(getApplicationContext(), PD_Shaomiao.class);
		 startActivity(intent);
	}
	public void btn_back_click(View v) {	
		PD_Shebeilist.this.finish();
	}
}
    
